package com.rjkj.medicalwaste.base

import android.graphics.Color
import android.text.TextUtils
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import com.google.android.material.snackbar.Snackbar
import com.rjkj.medicalwaste.R


fun DialogFragment.showTip(message: String) {
    if (TextUtils.isEmpty(message)) {
        return
    }
    Snackbar.make(requireView(), message, Snackbar.LENGTH_LONG).apply {
        view.setBackgroundColor(ContextCompat.getColor(requireContext(),R.color.black_grey))
        view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text).also {
            it.textSize = 28f
            it.setTextColor(Color.WHITE)
        }
    }.show()
}

/**
 * 初始化提示SnackBar注册
 * @param viewModel BaseViewModel
 */
fun DialogFragment.initTip(viewModel: BaseViewModel) {
    viewModel.tips.observe(viewLifecycleOwner, {
        it?.let {
            showTip(it)
            viewModel.onSnackBarShown()
        }
    })
}